package com.nutrition.health.repository;

import com.nutrition.health.model.User;
import com.nutrition.health.model.UserHealthProfile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserHealthProfileRepository extends JpaRepository<UserHealthProfile, Long> {
    
    Optional<UserHealthProfile> findByUser(User user);
    
    @Query("SELECT p FROM UserHealthProfile p JOIN FETCH p.user WHERE p.user.id = :userId")
    Optional<UserHealthProfile> findByUserId(@Param("userId") Long userId);
    
    @Query("SELECT p FROM UserHealthProfile p JOIN FETCH p.user")
    List<UserHealthProfile> findAllWithUser();
}